app.service('skuService',['$q','utilService',function($q,utilService){
    var _this_=this;

    _this_.update=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'sku/',
            data:$scope.data,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });

        return deferred.promise;
    }


    _this_.sku={
        shopId:1
    };

    _this_.addSku=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'sku',
            data:_this_.sku
        }).then(function(result){
            deferred.resolve(result);
        });

        return deferred.promise;
    }

    _this_.deleteSku=function($scope){

        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'sku/delete',
            data:{id:$scope.data.id},
            method:"PUT"
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    _this_.batchdeleteSku=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'sku/batch/delete',
            data:{ids:$scope.data},
            method:"PUT"
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    _this_.queryGoodsAboutSkuCount=function($scope,skuId){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'sku/use/count',
            params:{'skuId':skuId}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })
        return deferred.promise;
    }

}]);

